package com.doge.walknovel.api

import com.doge.walknovel.analysis.AppsFlyerHelper
import com.doge.walknovel.core.account.AccountHelper
import com.doge.walknovel.utils.*
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class ReqRespInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
            .newBuilder()
            .addHeader("Connection", "close")
            .addHeader("Accept-Language", language.language)
            .addHeader("deviceType", deviceType.toString())
            .addHeader("brand", android.os.Build.BRAND)
            .addHeader("model", android.os.Build.MODEL)
            .addHeader("osVersion", android.os.Build.VERSION.RELEASE)
            .addHeader("deviceNo", DeviceUtils.deviceId)
            .addHeader("version", appVersionCode.toString())
            .addHeader("x-auth-token", AccountHelper.token)
            .addHeader("afStatus",  AppsFlyerHelper.afStatus ?: "")
            .addHeader("origCost", AppsFlyerHelper.origCost ?: "")
            .addHeader("oaid", OAIDUtils.id ?: "")
            .addHeader("installReferrer", InstallReferUtils.referrer ?: "")
            .build()

        return chain.proceed(request)
    }
}